$(function(){
	var identification=createCustomOrderNo();
	$('#tocash_form').submit(function(){
		var bank_id = $('#tocash_form input[name="bank_id"]:checked').val();
		if(!bank_id||!jQuery.trim(bank_id)){
			//alert('请选择银行!');
			$.alert({
	    		status : 'error',
				basicTitle : '请选择银行!'
			});
			return false;
		}
		var amount = $('#tocash_form input[name="cashAmount"]');
		if(amount.val()==jQuery(amount).attr("data-placeholder")||amount.val() == ""){
			//alert('请输入充值金额!');
			$.alert({
	    		status : 'error',
				basicTitle : '请输入提现金额!'
			});
			return false;
		} 
		if(!$.check.isMoney(amount.val()))
		{
			$.alert({
	    		status : 'error',
				basicTitle : '请输入正确的提现金额!'
			});
			return false;
		}
		var aval = parseInt(amount.val());
		if(aval < parseInt(amount.attr('min')) || aval > parseInt(amount.attr('max'))){
			//alert('单笔提现限额 最低： 100 元，最高： 100000 元 !');
			$.alert({
	    		status : 'error',
				basicTitle : $.substitute('单笔提现限额 最低： {min} 元，最高： {max} 元 !',{min:amount.attr('min'),max:amount.attr('max')})
			});
			return false;
		}
		var password = $('#tocash_form input[name="cashPassword"]').val();
		if(password == ""){
			//alert('请输入资金密码!');
			$.alert({
	    		status : 'error',
				basicTitle : '请输入资金密码!'
			});
			return false;
		}
		$.ajax({
			url 	: window.frontPath + "bank/tocash_submit",
			method 	: 'POST',
			data    : {
				bankName: $('#tocash_form input[name="bank_id"]:checked').attr("bankName"),
				amount: aval,
				password: password,
				openingName:$('#openingName').val(),
				uname:$('#uname').val(),
				account:$('#bank_account').val(),
				identification:identification
			},
			success : function(data){
				if(!data.success){
					//alert(data.message);
					$.alert({
			    		status : 'error',
						basicTitle : data.message
					});
				}else{ 
					 reloadUserInfo();
					 $.alert({
				    		status : 'ok',
							basicTitle : "提现申请提交成功!",
						    buttons : [{'flag' : 'cancel' , 'name' : '继续提现' , 'handler' : function(){
									$.none_alert();
									location.reload(); 
									}
								},{'flag' : 'ok' , 'name' : '关闭' , 'handler' : function (){
									 $.none_alert();
									 location.href=window.frontPath+"home#/user/toCashLog";
							 }}]
						});
				}
			}
		});
		return false;
	});
	$.placeholder.init();
	$('.bank-radio').click(function(){
		var _this = $(this);
		$('#bank_account').val(_this.attr('bank_account'));
		$('#uname').val(_this.attr('uname'));
		$('#openingName').val(_this.attr('openingName'));
	});
	$('.bank-radio:eq(0)').click(); 
});


function showPaymentFee() {
	   $("#cashAmount").val($("#cashAmount").val().replace(/\D+/g, ''));
	   $("#chineseMoney").html(changeMoneyToChinese($("#cashAmount").val()));
	}